﻿Imports System.Data.SqlClient

Public Class members_left
    Inherits System.Web.UI.UserControl
    Private objrd As SqlDataReader = Nothing
    Private objfind As New GetData
    Private sSQL As String
    Private ps As New PreparedStatement(sSQL)
    Private userId As String

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If (Session("uid") <> Nothing And Session("uid") <> "") Then
            Dim userId, cid, strErr As String
            strErr = ""
            userId = Session("uid")

            Dim conn As SqlConnection = objfind.getConn()
            If (userId <> Nothing) Then
                ps.strSql = "select * from merchant where owner_id =@ownerId"
                ps.addParameter("ownerId", userId)
                objrd = objfind.dr(ps, strErr, conn, objrd)

                If (objrd.HasRows) Then
                    While objrd.Read
                        cid = objrd.Item("company_id")
                        yellowPage.HRef = "/english/company.aspx?cid=" & cid
                    End While
                Else
                    cid = System.Guid.NewGuid().ToString()
                    ps.strSql = "insert into merchant (company_id,active,owner_id) values (@cid,@active,@ownerId)"
                    ps.addParameter("cid", userId)
                    ps.addParameter("active", 1)
                    objfind.es(ps, strErr)
                    yellowPage.HRef = "/english/company.aspx?cid=" & cid
                End If
            End If
            objfind.closeConn(conn)
        End If
    End Sub

End Class